/**
* Created by wust on 2020-12-03 11:14:47.
*/
<template>
  <el-form ref="formModel" :model="formModel" :rules="rules" label-width="120px" style="width:70%;"
    @submit.native.prevent>
    <el-form-item label="code" prop="code">
      <el-input v-model="formModel.code"></el-input>
    </el-form-item>
    <el-form-item label="name" prop="name">
      <el-input v-model="formModel.name"></el-input>
    </el-form-item>
    <el-form-item label="description" prop="description">
      <el-input v-model="formModel.description"></el-input>
    </el-form-item>
    <el-form-item label="is_deleted" prop="isDeleted">
      <el-input v-model="formModel.isDeleted"></el-input>
    </el-form-item>

    <el-form-item style="text-align: left;">
      <el-button type="primary" @click="onSubmit('formModel')" :loading="submitting">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
  import Vue from 'vue'

  export default {
    name: 'post-update',
    props: ['selectedModel'],
    data() {
      return {
        submitting: false,
        formModel: {
          id: null,
          code: null,
          name: null,
          description: null,
          isDeleted: null,

        },
        rules: {}
      }
    },
    created: function() {
      this.formModel = this.selectedModel
    },
    methods: {
      onSubmit: function(formData) {
        this.$refs[formData].validate((valid) => {
          if (!valid) {} else {
            Vue.$ajax({
              method: 'put',
              url: Vue.$adminServerURL + '/web/v1/PostController',
              data: this.formModel
            }).then(res => {
              if (res.data.flag !== 'SUCCESS') {
                if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                  this.$message({
                    message: res.data.message,
                    type: 'warning'
                  })
                }
              } else {
                this.$message({
                  message: res.data.message,
                  type: 'success'
                })
              }
            })
          }
        })
      }
    }
  }
</script>
